package com.season.seasonStudy.javase.j_021_io;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;

public class testasd {
	public static void main(String[] args) {
		// File file = new File("f:/aaa.txt");
		// //创建文件
		// if (file.exists()) {
		// System.out.println("cunzai");
		// }
		// if(file.isFile()){
		// System.out.println("是一个文件");
		// }
		// if (file.isDirectory()) {
		//
		// }
		// System.out.println(""+file.getPath());
		//
		// System.out.println(""+file.getAbsolutePath());
		// System.out.println(""+file.getName());
		// System.out.println(""+file.length());
		// if (file.delete()) {
		// System.out.println();
		// }
		// try {
		// if (file.createNewFile()){
		// System.out.println();
		// }
		// } catch (Exception e) {
		// e.printStackTrace();
		// // TODO: handle exception
		// }
		//
		//
		// file.
		File file = new File("e:/wohenshuai/a.txt");
		File files = new File("e:/wohenshuai");
		try {
			files.mkdir();
			if (file.createNewFile()) {
				System.out.println("创建了这个文件");
//				if (file.isFile()){
//					System.out.println("yi");
//				}			
				System.out.println("");
			}else {
				System.out.println("文件存在");
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		FileInputStream fis =null;
		FileOutputStream fos = null;
		try {
			fis = new FileInputStream(file);
			System.out.println("文件长度："+file.length());
			byte[] a = new byte[1024];
			System.out.println("int:"+fis.available());
			for (int i = 0; i < fis.available(); i++) {
				System.out.println((char)a[i]);
			}
			
			
			byte[] b = new byte[]{'a','b','c'};
			
			
			
		} catch (Exception e) {
			// TODO: handle exception
		}	
		BufferedReader br = null;
		BufferedWriter bw = null;
		try {
			Reader r = new FileReader("e:/wohenshuai/before.txt");
			Writer w = new FileWriter("e:/wohenshuai/now.txt");
			br = new BufferedReader(r);
			bw = new BufferedWriter(w);
			StringBuffer sb = new StringBuffer();
			String s= null;
			while ((s=br.readLine()) != null) {
				sb.append(s);
			}
			s= sb.toString();
			System.out.println("之前的："+ s);
			s.replace("{name}", "狗狗");
			s.replace("{type}", "仔仔");
			s.replace("{master}", "纪杰");
			bw.write(s);
			System.out.println("现在的："+s);
				
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
	}
}
